<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/include/page.jsp"%>
<jsp:useBean id="pojo" class="com.jjh.users.pojo.AAdmins"/>
<!DOCTYPE HTML>
<html>
	<head>
		<%@ include file="/common/include/title.jsp"%>
		<link rel="stylesheet" href="${rootPath }/common/resource/H-ui.admin/lib/zTree/v3/css/zTreeStyle/zTreeStyle.css"
			type="text/css">
		<title>菜单列表 - 用户中心</title>
	</head>
	<body>
		<nav class="breadcrumb">
			<i class="Hui-iconfont">&#xe67f;</i> 首页
			<span class="c-gray en">&gt;</span> 用户管理
			<span class="c-gray en">&gt;</span> 授权列表
			<a class="btn btn-success radius r" style="line-height: 1.6em; margin-top: 3px"
				href="javascript:location.replace(location.href);" title="刷新">
				<i class="Hui-iconfont">&#xe68f;</i>
			</a>
		</nav>
		角色名称:${requestScope.role.name }
		<form id="form" action="${rootPath }/back/auth/roleMenuInsertSubmit" method="post">
			<input type="hidden" name="menuIds" id="menuIds" value="">
			<input type="hidden" name="roleId" value="${param.roleId }">
			<table class="table">
				<tr>
					<td class="va-t">
						<ul id="treeDemo" class="ztree"></ul>
					</td>
				</tr>
			</table>
			<div class="row cl">
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
					<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
				</div>
			</div>
		</form>
		<%@ include file="/common/include/footer.jsp" %>
		<!--请在下方写此页面业务相关的脚本-->
		<script type="text/javascript"
			src="${rootPath }/common/resource/H-ui.admin/lib/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script>
		<!--请在下方写此页面业务相关的脚本-->
		<script type="text/javascript" src="${rootPath }/common/resource/H-ui.admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
		<script type="text/javascript" src="${rootPath }/common/resource/H-ui.admin/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
		<script type="text/javascript" src="${rootPath }/common/resource/H-ui.admin/lib/jquery.validation/1.14.0/messages_zh.js"></script> 
		<script type="text/javascript">
			var setting = {
				check: {
					enable: true
				},
				view : {
					dblClickExpand : true,
					showLine : true,
					selectedMulti : false
				},
				data : {
					simpleData : {
						enable : true,
						idKey : "id",
						pIdKey : "pId",
						rootPId : ""
					}
				},
				callback : {
					beforeClick : function(treeId, treeNode) {
						var zTree = $.fn.zTree.getZTreeObj("tree");
						if (treeNode.isParent) {
							zTree.expandNode(treeNode);
							return false;
						} else {
							demoIframe.attr("src", treeNode.file + ".html");
							return true;
						}
					}
				}
			};
			
			/* 超级关键,它是内容 */
			var zNodes = [
			<c:forEach items="${requestScope.list}" var="listTemp" varStatus="stat">
				{
					id : ${listTemp.id},
					pId : ${listTemp.parentId},
					name :"${listTemp.name}",
					checked: ${listTemp.checkStr == '1' ? true : false},
					open : true,
				},
			</c:forEach>
			];
	
			var code;
	
			function showCode(str) {
				if (!code)
					code = $("#code");
				code.empty();
				code.append("<li>" + str + "</li>");
			}
	
			$(document).ready(function() {
				var t = $("#treeDemo");
				t = $.fn.zTree.init(t, setting, zNodes);
				demoIframe = $("#testIframe");
				//demoIframe.on("load", loadReady);
				var zTree = $.fn.zTree.getZTreeObj("tree");
				//zTree.selectNode(zTree.getNodeByParam("id",'11'));
				
				/*
					表单验证的框架;
					$();id选择器
				*/
				$("#form").validate({
					onkeyup:false,
					focusCleanup:true,
					success:"valid",
					submitHandler:function(form){
						var flag = formSubmit();
						if(!flag)
						{
							return ; 
						}
						
						$(form).ajaxSubmit({
							type: 'post',
							/* url: "${rootPath}/back/admin/adminsInsertSubmit" , */
							success: function(data){
								/**
									参数1:提示信息
									参数2:弹出信息的可选项;time:超时
									参数3:执行完以后调用此方法
									
									在ajax中,success方法的参数data就代码了服务器返回的内容
								*/
								var info = data.info ; 
								if(data.code == 0 )
								{
									info = info + "totalCount:" +  data.data.totalCount + ";succedCount:" + data.data.succedCount + ";failedCount:" + data.data.failedCount ; 
								}
								layer.msg(info,{icon:1,time:3000},function()
								{
									/* 成功 */
									if(data.code == '0')
									{
										/* 刷新父窗口 */
										var index = parent.layer.getFrameIndex(window.name);
										parent.$('.btn-refresh').click();
										/* 关闭当前窗口 */
										parent.layer.close(index);
									}
								});
							},
			                error: function(XmlHttpRequest, textStatus, errorThrown){
								layer.msg('error!',{icon:1,time:1000});
							},
							dataType:'json'
						});
					}
				});
			});
			
			function formSubmit()
			{
				/* 打断点 */
				var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
				var nodes = treeObj.getCheckedNodes();
				console.info(treeObj + "===结果===" + nodes)
				var sb = "" ; 
				for(var i = 0 ;i < nodes.length ; i ++)
				{
					/* 数组里面放的是选中的节点 */
					var nodeTemp = nodes[i]; 
					sb = sb + nodeTemp.id + "," ; 
				}
				
				$("#menuIds").val(sb);
				
				if(sb == "")
				{
					alert("==请选择菜单(这是前端)==")
					return false; 
				}
				return true ; 
			}
		</script>
	</body>
</html>